const http = require('http')
const url = require('url')

http.createServer((req,res) => {
  if(req.url == '/favicon.ico') {
    return
  }
  const urlObj = url.parse(req.url,true) // 第二个参数传true会解析query参数
  console.log(urlObj)
  switch(urlObj.pathname) {
    case "/api/jsonp":
      res.end(`${urlObj.query.callback}(${JSON.stringify({name:'zy',age:18})})`)
      break;
    default:
      res.end('404')
  }
}).listen(5555,() => {
  console.log('5555端口以启动')
})